package com.util;

import org.apache.commons.collections.map.LRUMap;


public class CacheUtil {
	
	private static CacheUtil instance;
	private LRUMap cacheMap = null;
	private CacheUtil(){
		SysConfig.getInteger("cache.entity");
		cacheMap = new LRUMap();
	}

	public static synchronized CacheUtil getInstance() {
		if(instance == null){
			instance = new CacheUtil();
		}
		return instance;
	}
	
	public BasePojo get(Class<BasePojo> basePojoClass,int id){
		return (BasePojo) cacheMap.get(basePojoClass.getName()+"_"+id);
	}
	
	public void put(BasePojo obj){
		cacheMap.put(obj.getClass().getName()+"_"+obj.getId(), obj);
	}	
	
	public void remove(BasePojo obj){
		cacheMap.remove(obj.getClass().getName()+"_"+obj.getId());
	}
	
	public void reset(){
		instance = new CacheUtil();
	}
	
	public int getEntityCount(){
		return instance.cacheMap.size();
	}

}
